<template>
  <!-- 房内人员设定 -->
  <div class="door">
    <div v-if="isauth('lock_edit')">
      <!-- 时间批量修改 -->
      <div>
        <el-button type="primary" @click="showPass()" size="mini"
          >添加密码</el-button
        >
        <el-button type="danger" @click="onDelete" size="mini"
          >取消密码</el-button
        >
        <div class="time">
          <b>延长授权时间:</b>
          <el-button type="primary" @click="oneDay(1)" size="mini"
            >一天</el-button
          >
          <el-button type="primary" @click="oneDay(7)" size="mini"
            >一周</el-button
          >
          <el-button type="primary" @click="oneDay(30)" size="mini"
            >一月</el-button
          >
          <el-button type="primary" @click="oneDay(365)" size="mini"
            >一年</el-button
          >
          <el-button type="primary" @click="resetTime()" size="mini"
            >置为当前时间</el-button
          >
        </div>
      </div>

      <!-- 星期时段批量修改 -->
      <div class="TimeWeek">
        <b>星期时段:</b>
        <span>一</span>
        <el-select
          v-model="valMonday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valMonday, 'mondayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <span>二</span>
        <el-select
          v-model="valTuesday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valTuesday, 'tuesdayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <span>三</span>
        <el-select
          v-model="valWednesday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valWednesday, 'wednesdayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <span>四</span>
        <el-select
          v-model="valThursday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valThursday, 'thursdayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <span>五</span>
        <el-select
          v-model="valFriday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valFriday, 'fridayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <span>六</span>
        <el-select
          v-model="valSaturday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valSaturday, 'saturdayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <span>日</span>
        <el-select
          v-model="valSunday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valSunday, 'sundayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
        <b>假日时段:</b>
        <el-select
          v-model="valHoliday"
          placeholder="请选择"
          size="mini"
          style="width: 62px"
          @change="handleValOne(valHoliday, 'holidayTimeStageIndex')"
        >
          <el-option
            v-for="item in 16"
            :key="item - 1"
            :label="item - 1"
            :value="item - 1"
          ></el-option>
        </el-select>
      </div>
    </div>
    <!-- 房内人员信息显示 -->
    <div class="my_table">
      <el-table
        v-loading="loading"
        :data="detailslist"
        ref="table"
        border
        highlight-current-row
        style="width: 100%"
        @selection-change="cellClick"
        max-height="450"
        :header-cell-style="(header) => headFirst(header, 2)"
        :disabled="true"
        :cell-style="(res) => headFirst_col(res, [], 2)"
      >
        <!-- v-if="isauth('lock_edit')" -->
        <el-table-column type="selection" width="40px" align="center"></el-table-column>
        <el-table-column
          prop="terminalName"
          label="设备名称"
          align="center"
          min-width="120px"
        >
        </el-table-column>
        <!-- 时效密码 -->
        <el-table-column
          prop="tempPassword"
          label="时效密码"
          align="center"
          min-width="90px"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="userName"
          label="姓名"
          v-if="formThead.userName.checked"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="userNumber"
          label="编号"
          v-if="formThead.userNumber.checked"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="cardNumber"
          label="卡号"
          v-if="formThead.cardNumber.checked"
          align="center"
          min-width="110px"
        ></el-table-column> -->
        <!-- 开始时间 -->
        <el-table-column
          prop="startTime"
          label="有效开始日期"
          align="center"
          min-width="190px"
        >
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.startTime"
              type="datetime"
              placeholder="选择日期时间"
              @change="handleSelect(scope.row, true)"
              value-format="yyyy-MM-dd HH:mm:ss"
              size="mini"
              style="width: 180px"
              :clearable="false"
              :disabled="
                scope.row.updateFlag == 3 ||
                !isauth('lock_edit') ||
                !isauth('lock_edit')
              "
              default-time="00:00:00"
            ></el-date-picker>
          </template>
        </el-table-column>
        <!-- 有效时间 -->
        <el-table-column
          prop="endTime"
          label="有效结束日期"
          v-if="formThead.endTime.checked"
          align="center"
          min-width="190px"
        >
          <template slot-scope="scope">
            <!-- :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')" -->
            <el-date-picker
              v-model="scope.row.endTime"
              type="datetime"
              placeholder="选择日期时间"
              @change="handleSelect(scope.row)"
              value-format="yyyy-MM-dd HH:mm:ss"
              size="mini"
              style="width: 180px"
              :clearable="false"
              :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              default-time="23:59:59"
            ></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
          prop="backLock"
          label="反锁开门"
          v-if="formThead.backLock.checked"
          align="center"
          width="40px"
        >
          <template slot-scope="scope">
            <el-checkbox
              v-model="scope.row.backLock"
              :checked="scope.row.backLock"
              @change="handleChange(scope.row, 'backLock')"
              :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
            ></el-checkbox>
          </template>
        </el-table-column>
        <!-- 开门-礼拜 -->
        <el-table-column
          prop="Sunday"
          label="星期"
          v-if="formThead.Sunday.checked"
          align="center"
        >
          <el-table-column
            prop="monday"
            label="一"
            v-if="formThead.monday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.monday"
                :checked="scope.row.monday"
                @change="handleChange(scope.row, 'monday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="tuesday"
            label="二"
            v-if="formThead.tuesday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.tuesday"
                :checked="scope.row.tuesday"
                @change="handleChange(scope.row, 'tuesday', scope.$index)"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="wednesday"
            label="三"
            v-if="formThead.wednesday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.wednesday"
                :checked="scope.row.wednesday"
                @change="handleChange(scope.row, 'wednesday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="thursday"
            label="四"
            v-if="formThead.thursday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.thursday"
                :checked="scope.row.thursday"
                @change="handleChange(scope.row, 'thursday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="friday"
            label="五"
            v-if="formThead.friday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.friday"
                :checked="scope.row.friday"
                @change="handleChange(scope.row, 'friday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="saturday"
            label="六"
            v-if="formThead.saturday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.saturday"
                :checked="scope.row.saturday"
                @change="handleChange(scope.row, 'saturday')"
              ></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="sunday"
            label="日"
            v-if="formThead.sunday.checked"
            align="center"
            width="40px"
          >
            <template slot-scope="scope">
              <el-checkbox
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
                v-model="scope.row.sunday"
                :checked="scope.row.sunday"
                @change="handleChange(scope.row, 'sunday')"
              ></el-checkbox>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- 星期时段 -->
        <el-table-column
          prop="SundayTime"
          label="星期时段"
          v-if="formThead.SundayTime.checked"
          align="center"
        >
          <el-table-column
            prop="mondayTimeStageIndex"
            label="一"
            v-if="formThead.mondayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.mondayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="tuesdayTimeStageIndex"
            label="二"
            v-if="formThead.tuesdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.tuesdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>

          <el-table-column
            prop="wednesdayTimeStageIndex"
            label="三"
            v-if="formThead.wednesdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.wednesdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>

          <el-table-column
            prop="thursdayTimeStageIndex"
            label="四"
            v-if="formThead.thursdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.thursdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="fridayTimeStageIndex"
            label="五"
            v-if="formThead.fridayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.fridayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="saturdayTimeStageIndex"
            label="六"
            v-if="formThead.saturdayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.saturdayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="sundayTimeStageIndex"
            label="日"
            v-if="formThead.sundayTimeStageIndex.checked"
            align="center"
            width="82px"
          >
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.sundayTimeStageIndex"
                placeholder="请选择"
                size="mini"
                @change="handleSelect(scope.row)"
                :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
              >
                <el-option
                  v-for="item in 16"
                  :key="item - 1"
                  :label="item - 1"
                  :value="item - 1"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table-column>
        <!-- 假日时段 -->
        <el-table-column
          prop="holidayTimeStageIndex"
          label="假日时段"
          v-if="formThead.holidayTimeStageIndex.checked"
          align="center"
          width="82px"
        >
          <template slot-scope="scope">
            <el-select
              v-model="scope.row.holidayTimeStageIndex"
              placeholder="请选择"
              size="mini"
              @change="handleSelect(scope.row)"
              :disabled="scope.row.updateFlag == 3 || !isauth('lock_edit')"
            >
              <el-option
                v-for="item in 16"
                :key="item - 1"
                :label="item - 1"
                :value="item - 1"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>

        <!-- 授权状态 -->
        <el-table-column
          prop="empowerType"
          label="授权状态"
          v-if="formThead.empowerType.checked"
          align="center"
          min-width="110px"
        >
          <template slot-scope="scope">
            <span
              >{{ scope.row.updateFlag | updateFlagType
              }}{{ scope.row.downloadState | downloadStateType }}</span
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChangepage"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="recordCount"
      ></el-pagination>
    </div>
    <el-dialog
      :title="operation ? '添加时效密码' : '修改时效密码'"
      :visible.sync="subscribe"
      width="500px"
      center
      :close-on-click-modal="false"
      :before-close="closeDialog"
      append-to-body
    >
      <el-form
        :model="addFrom"
        :rules="rules"
        ref="addFrom"
        label-width="120px"
      >
        <el-form-item label="开门密码:" prop="tempPassword">
          <el-col :span="20">
            <el-input
              size="mini"
              v-model="addFrom.tempPassword"
              style="width: 180px"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="有效开始时间:" prop="startTime">
          <el-col :span="24">
            <el-date-picker
              style="width: 180px"
              v-model="addFrom.startTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="datetime"
              size="mini"
            ></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="有效结束时间:" prop="endTime">
          <el-col :span="24">
            <el-date-picker
              style="width: 180px"
              v-model="addFrom.endTime"
              value-format="yyyy-MM-dd HH:mm:ss"
              default-time="23:59:59"
              type="datetime"
              size="mini"
            ></el-date-picker>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="subscribeAdd()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import bus from "@/bus.js";
export default {
  data() {
    return {
      loading: false,
      detailslist: [],
      pageNum: 1,
      pageSize: 10,
      currentPage: 1,
      recordCount: 0,
      searchInfo: {},
      //消费汇总
      formThead: {
        userName: {
          label: "用户",
          prop: "userName",
          checked: true,
        },
        userNumber: {
          label: "编号",
          prop: "userNumber",
          checked: true,
        },
        cardNumber: {
          label: "卡号",
          prop: "cardNumber",
          checked: true,
        },
        endTime: {
          label: "开门有效期",
          prop: "endTime",
          checked: true,
        },
        backLock: {
          label: "反锁开门",
          prop: "backLock",
          checked: true,
        },
        Sunday: {
          label: "星期",
          prop: "backLock",
          checked: true,
        },
        monday: {
          label: "星期一",
          prop: "monday",
          checked: true,
        },

        tuesday: {
          label: "星期二",
          prop: "tuesday",
          checked: true,
        },
        wednesday: {
          label: "星期三",
          prop: "wednesday",
          checked: true,
        },
        thursday: {
          label: "星期四",
          prop: "thursday",
          checked: true,
        },
        friday: {
          label: "星期五",
          prop: "friday",
          checked: true,
        },
        saturday: {
          label: "星期六",
          prop: "saturday",
          checked: true,
        },
        sunday: {
          label: "星期日",
          prop: "sunday",
          checked: true,
        },
        SundayTime: {
          label: "星期时段",
          prop: "SundayTime",
          checked: true,
        },
        mondayTimeStageIndex: {
          label: "星期一",
          prop: "mondayTimeStageIndex",
          checked: true,
        },
        tuesdayTimeStageIndex: {
          label: "星期二",
          prop: "tuesdayTimeStageIndex",
          checked: true,
        },
        wednesdayTimeStageIndex: {
          label: "星期三",
          prop: "wednesdayTimeStageIndex",
          checked: true,
        },
        thursdayTimeStageIndex: {
          label: "星期四",
          prop: "thursdayTimeStageIndex",
          checked: true,
        },
        fridayTimeStageIndex: {
          label: "星期五",
          prop: "fridayTimeStageIndex",
          checked: true,
        },
        saturdayTimeStageIndex: {
          label: "星期六",
          prop: "saturdayTimeStageIndex",
          checked: true,
        },
        sundayTimeStageIndex: {
          label: "星期七",
          prop: "sundayTimeStageIndex",
          checked: true,
        },
        holidayTimeStageIndex: {
          label: "假日时段",
          prop: "holidayTimeStageIndex",
          checked: true,
        },
        empowerType: {
          label: "授权状态",
          prop: "empowerType",
          checked: true,
        },
      },
      // 被选中的数据
      optPersonnel: [],
      // 星期时段多选
      valMonday: 0,
      valTuesday: 0,
      valWednesday: 0,
      valThursday: 0,
      valFriday: 0,
      valSaturday: 0,
      valSunday: 0,
      // 假日时段
      valHoliday: 0,
      // true为添加，false为修改
      operation: true,
      subscribe: false,
      addFrom: {
        // 流水号
        tempPassword: "",
        startTime: "",
        endTime: "",
      },
      rules: {
        tempPassword: [
          { required: true, message: "请输入开门密码", trigger: "blur" },
        ],
        startTime: [
          { required: true, message: "请选择有效开始时间", trigger: "blur" },
        ],
        endTime: [
          { required: true, message: "请输入有效结束时间", trigger: "blur" },
        ],
      },
    };
  },

  created() {
    this.addFrom.startTime = this.getNowTime("yy-mm-dd 00");
    this.addFrom.endTime = this.getNowTime("yy-mm-dd 59");
    this.userGuid = sessionStorage.getItem("administrator");
    this.gestatistics();
  },
  filters: {
    handleEmpowerType(empower) {
      if (empower == 0) {
        return "未授权";
      }
      if (empower == 1) {
        return "指定房间";
      }
      if (empower == 2) {
        return "临时授权";
      }
      if (empower == 2) {
        return "导入授权";
      }
    },
    updateFlagType(val) {
      val = Number(val);
      switch (val) {
        case 1:
          return "新增,";
          break;
        case 2:
          return "覆盖,";
          break;
        case 3:
          return "删除,";
          break;
      }
    },
    downloadStateType(val) {
      val = Number(val);
      switch (val) {
        case 0:
          return "未下载";
          break;
        case 1:
          return "下载成功";
          break;
        case 2:
          return "设备名单已满";
          break;
        case 5:
          return "名单内容有误";
          break;
        case 6:
          return "找不到对应的设备";
          break;
        case 7:
          return "名单已过期";
          break;
      }
    },
  },
  computed: {
    changeschoolid: {
      get() {
        return this.$store.state.user.changeschoolid;
      },
    },
  },
  mounted() {
    bus.$on("listenToA", this.getHeaderDate);
  },
  props: [
    "datetime",
    "unitGuid",
    "consumptionpoint",
    "radio",
    "roomGuid",
    "terminalGuid",
    "terminalName",
  ],
  methods: {
    // 多选框是否选中
    handleChange(row, key, b) {
      // if (row[key] == false) {
      //   row[key] = true;
      // } else if (row[key] == true) {
      //   row[key] = false
      // } else if (row[key] == null) {
      //   row[key] = true
      // }
      if (this.optPersonnel.indexOf(row) == -1) {
        if (row) {
          this.$refs.table.toggleRowSelection(row);
        }
      }
    },
    // 选择器选中后触发，让表格选中
    handleSelect(row, is) {
      if (is && row.startTime > row.endTime) {
        this.$message({
          message: "开始时间不能大于结束时间",
          type: "warning",
        });
        row.startTime = row.endTime;
      }
      if (this.optPersonnel.indexOf(row) == -1) {
        if (row) {
          this.$refs.table.toggleRowSelection(row);
        }
      }
    },
    // 获取到房内人员授权信息
    gestatistics() {
      this.loading = true;
      this.$http({
        url: this.$http.adornUrl(
          "/terminal/doorLock/lock-date-time-password-search"
        ),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            searchInfo: {
              roomGuid: this.roomGuid,
              unitGuid: this.changeschoolid,
            },
          },
          messageType: 0,
        }),
      }).then(({ data }) => {
        this.loading = false;
        if (data.messageCode == 200) {
          console.log(data);
          this.detailslist = data.messageContent.data;
          this.recordCount = data.messageContent.recordCount;
          this.currentPage = data.messageContent.pageNum;
          this.detailslist.map(item => {
            item.backLock = item.backLock == 1 ? true : false
            item.friday = item.friday == 1 ? true : false
            item.monday = item.monday == 1 ? true : false
            item.saturday = item.saturday == 1 ? true : false
            item.sunday = item.sunday == 1 ? true : false
            item.thursday = item.thursday == 1 ? true : false
            item.tuesday = item.tuesday == 1 ? true : false
            item.wednesday = item.wednesday == 1 ? true : false
          })
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.gestatistics();
    },
    handleCurrentChangepage(val) {
      this.pageNum = val;
      this.gestatistics();
    },
    getHeaderDate(val) {
      this.formThead = val;
    },
    // 表格多选操作之后触发
    cellClick(row) {
      this.optPersonnel = row;
      console.log();
      let a = row.lenght || false;
      console.log(a);
      console.log(row);
      if (row.lenght != 0) {
        row.map((item) => {
          if (item.updateFlag == "未授权") {
            item.backLock = 0;
            item.endTime = this.getimeto("yyyy-MM-dd HH:mm:ss");
            item.friday = 0;
            item.fridayTimeStageIndex = 0;
            item.holidayTimeStageIndex = 0;
            item.monday = 0;
            item.mondayTimeStageIndex = 0;
            // item.pkNamelistId = 0;
            item.saturday = 0;
            item.saturdayTimeStageIndex = 0;
            item.sunday = 0;
            item.sundayTimeStageIndex = 0;
            item.thursday = 0;
            item.thursdayTimeStageIndex = 0;
            item.tuesday = 0;
            item.tuesdayTimeStageIndex = 0;
            item.wednesday = 0;
            item.wednesdayTimeStageIndex = 0;
          }
        });
      }
    },
    // 增加选中人的时间
    oneDay(day) {
      if (this.optPersonnel.length == 0) {
        return false;
      }
      let arr = [];
      let timer = 0;
      this.optPersonnel.map((item) => {
        // item.updateFlag = 3;
        if (item.updateFlag != 3) {
          if (item.endTime) {
            timer = item.endTime;
            arr = timer.split("-");
            // 月份处理
            if (day == 30) {
              if (Number(arr[1]) % 2 == 1 && Number(arr[1]) <= 7) {
                day = 31;
              } else if (Number(arr[1]) == 2) {
                //判断闰年还是平年
                if (
                  (Number(arr[0]) % 4 == 0 && Number(arr[0]) % 100 != 0) ||
                  Number(arr[0]) % 400 == 0
                ) {
                  day = 29;
                } else {
                  day = 28;
                }
              } else if (
                Number(arr[1]) % 2 == 0 &&
                Number(arr[1]) <= 12 &&
                Number(arr[1]) > 7
              ) {
                day = 31;
              }
            }
            // 年份处理
            if (day == 365) {
              //判断闰年还是平年
              if (
                (Number(arr[0]) % 4 == 0 && Number(arr[0]) % 100 != 0) ||
                Number(arr[0]) % 400 == 0
              ) {
                day = 366;
              }
            }
            console.log(item.endTime);
            console.log(Number(new Date(item.endTime).getTime()));
            console.log(
              Number(new Date(item.endTime).getTime()) +
                Number(1000 * 60 * 60 * 24)
            );
            timer = new Date(
              new Date(item.endTime).getTime() + 1000 * 60 * 60 * 24 * day
            );
            console.log(timer);
            let Y = timer.getFullYear() + "-";
            let M =
              (timer.getMonth() + 1 < 10
                ? "0" + (timer.getMonth() + 1)
                : timer.getMonth() + 1) + "-";
            let D =
              timer.getDate() < 10 ? "0" + timer.getDate() : timer.getDate();
            let h =
              timer.getHours() < 10
                ? "0" + timer.getHours()
                : +timer.getHours();
            let m =
              timer.getMinutes() < 10
                ? "0" + timer.getMinutes()
                : +timer.getMinutes();
            let s =
              timer.getSeconds() < 10
                ? "0" + timer.getSeconds()
                : +timer.getSeconds();
            item.endTime = Y + M + D + " " + h + ":" + m + ":" + s;
          }
        }
      });
    },
    // 批量重置时间
    resetTime() {
      if (this.optPersonnel.length == 0) {
        return false;
      }
      this.optPersonnel.map((item) => {
        if (item.updateFlag != 3) {
          item.endTime = this.getimeto("yyyy-MM-dd HH:mm:ss");
        }
      });
    },

    // 批量修改星期时段
    handleValOne(val, key) {
      if (this.optPersonnel.length == 0) {
        return false;
      }

      this.optPersonnel.map((item) => {
        // item.updateFlag = 3;
        if (item.updateFlag != 3) {
          item[key] = val;
        }
      });
    },
    // 取消添加弹窗
    closeDialog() {
      this.subscribe = false;
    },
    // 确定添加
    subscribeAdd() {
      this.$refs["addFrom"].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              "/terminal/doorLock/lock-date-time-password-add"
            ),
            method: "post",
            data: this.$http.adornData({
              messageContent: {
                roomGuid: this.roomGuid,
                terminalType: 22,
                unitGuid: this.changeschoolid,
                terminalGuid: this.terminalGuid,
                tempPassword: this.addFrom.tempPassword,
                startTime: this.addFrom.startTime,
                endTime: this.addFrom.endTime,
              },
              messageType: 0,
            }),
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              console.log(data);
              this.$message({
                message: "添加成功",
                type: "success",
              });
              this.subscribe = false;
              this.gestatistics();
            } else {
              this.$message.error(data.errorMessage);
            }
          });
        }
      });
    },

    // 点击查询后触发
    showPass() {
      this.subscribe = true;
      this.$nextTick(() => {
        this.$refs["addFrom"].resetFields();
      });
    },
    // 保存修改
    preservation() {
      // 清楚不需要的参数
      let arr = JSON.parse(JSON.stringify(this.optPersonnel));
       arr.map(item => {
          item.backLock = item.backLock ? 1 : 0
          item.friday = item.friday ? 1 : 0
          item.monday = item.monday ? 1 : 0
          item.saturday = item.saturday ? 1 : 0
          item.sunday = item.sunday ? 1 : 0
          item.thursday = item.thursday ? 1 : 0
          item.tuesday = item.tuesday ? 1 : 0
          item.wednesday = item.wednesday ? 1 : 0
        })
      this.$http({
        url: this.$http.adornUrl(
          "/terminal/doorLock/lock-date-time-password-update"
        ),
        method: "post",
        data: this.$http.adornData({
          messageContent: {
            nameList: arr,
            roomGuid: this.roomGuid,
            unitGuid: this.changeschoolid,
          },
          messageType: 0,
        }),
      }).then(({ data }) => {
        // console.log(data);
        if (data.messageCode == 200) {
          this.$message({
            message: "保存成功",
            type: "success",
          });
          this.gestatistics();
          return true;
        } else {
          this.$message.error(data.errorMessage);
        }
      });
    },
    // 删除选中数据，取消授权
    onDelete() {
      let namelistGuid = [];
      if (this.optPersonnel.length == 0) {
        this.$message({
          message: "请勾选需要删除的数据",
          type: "warning",
        });
        return false;
      }
      this.optPersonnel.map((item) => {
        namelistGuid.push(item.namelistGuid);
      });

      this.$confirm("此操作将永久取消密码, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http({
            url: this.$http.adornUrl("/terminal/doorLock/empower-name-delete"),
            method: "post",
            data: this.$http.adornData({
              messageContent: {
                namelistGuid: namelistGuid,
                unitGuid: this.changeschoolid,
                userGuid: this.userGuid,
                roomGuid: this.roomGuid,
              },
              messageType: 0,
            }),
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                message: "删除成功",
                type: "success",
              });
              this.gestatistics();
            } else {
              this.$message.error(data.errorMessage);
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  display: flex;
  justify-content: center;
  align-items: center;
}
.door {
  //滚动条的宽度
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  //滚动条的滑块
  ::-webkit-scrollbar-thumb {
    background-color: #a1a3a9;
    border-radius: 3px;
  }
  .time {
    display: inline-block;
    margin-left: 30px;
  }
}
.TimeWeek {
  padding: 20px 0 10px 0;
}
.el-dialog--center .el-dialog__body {
  padding: 0 50px;
}
// 隐藏纵向滚动条
</style>